package cn.com.homeyoda.aimate.aihealth.ui.yasee;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.lifecycle.ViewModelProviders;

import com.wzq.mvvmsmart.utils.GlideLoadUtils;
import com.wzq.mvvmsmart.utils.ToastUtils;

import cn.com.homeyoda.aimate.aihealth.BR;
import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.app.AppViewModelFactory;
import cn.com.homeyoda.aimate.aihealth.base.BaseActivity;
import cn.com.homeyoda.aimate.aihealth.data.ExaminationDetail;
import cn.com.homeyoda.aimate.aihealth.databinding.ActivityYaseeCheckResultBinding;

public class YaseeCheckResultActivity extends BaseActivity<ActivityYaseeCheckResultBinding, YaseeCheckResultViewModel> implements View.OnClickListener {

    public static void start(Context context, String id) {
        Intent starter = new Intent(context, YaseeCheckResultActivity.class);
        starter.putExtra("id", id);
        context.startActivity(starter);
    }

    @Override
    public YaseeCheckResultViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(YaseeCheckResultViewModel.class);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_yasee_check_result;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        String id = getIntent().getStringExtra("id");
        viewModel.fetchExaminationDetail(id);
        initView();
    }

    private void initView() {
        binding.titleBar.tvTitle.setText("检测结果");
        binding.titleBar.ivBack.setOnClickListener(this);
        binding.tvArchiveLink.setOnClickListener(this);
        binding.btnBind.setOnClickListener(this);
        binding.btnDownload.setOnClickListener(this);
    }

    private void setData(ExaminationDetail.DataBean data) {
        GlideLoadUtils.loadImg(binding.ivMemberAvatar, data.getAvatar(), R.mipmap.ic_member1);

        binding.tvMemberName.setText(data.getName());
        binding.tvMemberGender.setText(data.getSex() == 1 ? "男" : "女");
        binding.tvMemberAge.setText(data.getAge() + "岁");
        binding.tvMemberHeightValue.setText(data.getHeight() + "CM");
        binding.tvMemberWeightValue.setText(data.getWeight() + "KG");
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.examinationDetailData.observe(this, this::setData);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            finish();
        } else if (id == R.id.tv_archive_link) {
            ToastUtils.showShort("查看健康档案");
        } else if (id == R.id.btn_bind) {
            ToastUtils.showShort("绑定账号");
        } else if (id == R.id.btn_download) {
            ToastUtils.showShort("下载报告");
        }
    }
}